import {queryById} from 'services/order'
import pathToRegexp from "path-to-regexp"

export default {
  namespace: 'orderDetail',

  state: {
    orderId: 0,
  },

  subscriptions: {
    setup ({dispatch, history}) {
      history.listen(({pathname}) => {
        const match = pathToRegexp('/orders/:id').exec(pathname)
        if (match) {
          dispatch({
            type: 'updateState',
            payload: {orderId: match[1]}
          })
        }
      })
    },
  },

  effects: {},

  reducers: {
    updateState (state, {payload}) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}
